package com.topdt.jbpm.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thx.common.service.BaseManager;
import com.topdt.jbpm.dao.ActivityDao;
import com.topdt.jbpm.dao.ActorDefinDetailDao;
import com.topdt.jbpm.dao.FlowDetailDao;
import com.topdt.jbpm.model.Activity;
import com.topdt.jbpm.model.FlowDetail;

/**
 * 
 * 建立日期 : 2013-7-19 上午11:48:14<br>
 * 作者 : 武海峰<br>
 * 模块 : <br>
 * 描述 : <br>
 * 修改历史: 序号 日期 修改人 修改原因 <br>
 * 1 <br>
 * 2 <br>
 */
@Service
@Transactional(readOnly = true)
public class FlowDetailService extends BaseManager<FlowDetail>{

	@Autowired
	private FlowDetailDao flowDetailDao;
	@Autowired
	private ActivityDao activityDao;
	@Autowired
	private ActorDefinDetailDao actorDefinDetailDao;

	public List<FlowDetail> findByFlowId(String flowId) {
		return flowDetailDao.findByFlowId(flowId);
	}

	public List<FlowDetail> getVersionByFlowId(String flowId) {
		return flowDetailDao.getVersionByFlowId(flowId);
	}
	
	@Transactional(readOnly = false)
	public void deleteByFlowId(String flowId) {
		flowDetailDao.deleteByFlowId(flowId);
	}
	
	/**
	 * 删除工作流程详细信息
	 * 包括：活动、活动处理人
	 * @param flowDetail
	 */
	@Transactional(readOnly = false)
	public void delFlowDetail(FlowDetail flowDetail) {
		List<Activity> activities = activityDao.findByFlowDetailId(flowDetail.getDetailId());
		if (activities != null && activities.size() > 0) {
			for (Activity activity : activities) {
				//删除活动处理人
				actorDefinDetailDao.delByActivityId(activity.getActivityId());
				//删除活动
				activityDao.delete(activity.getActivityId());
			}
		}
		//删除流程详细
		flowDetailDao.delete(flowDetail.getDetailId());
	}
	public FlowDetail getDetailByJbpmflowId(String jbpmFlowId) {
		return flowDetailDao.getDetailByJbpmflowId(jbpmFlowId);
	}
}
